package com.sike.action;
/**
 * 
 * @company sikejiaoyu
 */
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Controller
public class BaseAction {
	public Map<String,Object> getParameters(){
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder
			      .getRequestAttributes()).getRequest();
		Map req = request.getParameterMap();
		
		if(req!=null && !req.isEmpty()){
			Map p = new HashMap();
			java.util.Collection keys = req.keySet();
			for(Iterator i = keys.iterator();i.hasNext();){
				Object key = i.next();
				Object value = req.get(key);
				Object v =null;
				if(value.getClass().isArray()&&((Object[]) value).length==1){
					v =((Object[]) value)[0];					
				}else{
					v=value;
				}
				if(v != null && (v instanceof String) ){
					String s=((String)v).trim();
					if(s.length()>0)
						p.put(key,s );
				}
			}
			return p;
		}else{
			return null;
		}
	}
}
